import {supervise} from "@/handles/handle-list/summary/modules/supervise-set";
import {useSuperviseSetStore} from "@/store/modules/summary/supervise-set";
import globalData from "@/plugins/data";
import api from "@/api";
import {getDateString} from "@/plugins/methods";

const superviseSetStore = useSuperviseSetStore();
const json = {
  "detailId": "",
  "supervisorIds": "-1042970111192971164,7926317438430301040,-5658473716201142801,-2750019908142611072,",
  "supervisorNames": "aa、bb、cc、dd",
  "awakeDate": "2024-01-10 15:55",
  "title": "3234234",
  "unCancelledVisor": "",
  "role": "",
  "templateDateTerminal": "",
  "superviseType": "1",
  "moduleId": "2618123996037858328",
  "description": "",
  "isModifySupervise": "1",
  "hasLoad": "1"
}

function saveOrUpdate() {
  if (superviseSetStore.readOnly || !superviseSetStore.isModifySupervise) {
    console.log('只读，或者没有修改');
    return;
  }
  const {
    detailId,
    supervisorIds,
    superviseTitle: title,
    superviseAwakeDate: awakeDate,
    unCancelledVisor = '',
    role = '',
    supervisorNames = '',
    isModifySupervise
  } = superviseSetStore;
  let jsonParams = {
    detailId,
    supervisorIds,
    title,
    unCancelledVisor,
    role,
    supervisorNames,
    awakeDate: awakeDate ? getDateString(awakeDate) : '',
    superviseType: '1',
    moduleId: globalData.summaryId,
    isModifySupervise: isModifySupervise ? '1' : '0'
  }
  api.commonSaveSupervisor(JSON.stringify(jsonParams))
}

export default function () {
  return new Promise((resolve) => {
    supervise.call(this, resolve);
  }).then((res) => {
    if (res === true && !superviseSetStore.readOnly) {
      //点击了确认 单独发送保存督办数据
      saveOrUpdate();
    }
  });
}